<?php

namespace App\Eloquent;


class Article extends Model
{
    protected $table='articles';


    //查询该文章的上一条文章
    public function prev(){
        return Article::where('article_category_id',$this->article_category_id)
            ->where('display',1)
            ->where('published_at','<=',date('Y-m-d H:i:s'))
            ->where('published_at','>',$this->published_at)
            ->orderBy('published_at','asc')
            ->first();
    }
    //查询该文章的下一条文章
    public function next(){
        return Article::where('article_category_id',$this->article_category_id)
            ->where('display',1)
            ->where('published_at','<=',date('Y-m-d H:i:s'))
            ->where('published_at','<',$this->published_at)
            ->orderBy('published_at','desc')
            ->first();
    }
}
